package android.Dominion.Graph;

import java.util.HashMap;

//cannot proceed past this node until each node in WaitList has returned a response 
public class WaitNode extends GraphNode
{

	private HashMap<Integer, GraphNode> waitForList;
	private boolean stillWaiting;

	// add a node to wait for a response from
	public void AddWaitFor(GraphNode node)
	{
		waitForList.put(node.getId(), null);
	}

	public void AddResponce(GraphNode response) throws Exception
	{
		if (waitForList.containsKey(response.getId()))
		{
			waitForList.put(response.getId(), response);
		} else
		{
			throw new Exception("The responce Id was not found!");
		}

		// now we update stillWaiting
		stillWaiting = false;
		for (GraphNode node : waitForList.values())
		{
			if (node == null)
			{
				stillWaiting = true;
				break;
			}
		}
	}

	public void setWaitForList(HashMap<Integer, GraphNode> waitForList)
	{
		this.waitForList = waitForList;
	}

	public HashMap<Integer, GraphNode> getWaitForList()
	{
		return waitForList;
	}

	public void setStillWaiting(boolean stillWaiting)
	{
		this.stillWaiting = stillWaiting;
	}

	public boolean isStillWaiting()
	{
		return stillWaiting;
	}

}
